


#include "../../1_Application/Include/APP_WorkingNormalState.h"




#include "../../4_Library/Include/general.h"
#include "../../4_Library/Include/Int.h"
#include "../../4_Library/Include/Lib_UartComm.h"
#include "../../4_Library/Include/Lib_CommSubMicom.h"
#include "../../4_Library/Include/Lib_SensingADC.h"
#include "../../4_Library/Include/Lib_EEPROM.h"




static UINT16 ulDetect_CurVoltage;

enum
{
	LowVolt = 1,
	HighVlot,
};

void VC_Get_Vdc(void)
{
/*
	INT32 slVdcSum = 0;
	UINT32 ultemp = 0;
	UINT32 slDetect_CurVoltage = 0;

	static UINT16 ucVdcCnt = 0;
	static UINT32 ulVdcSum = 0;

	if(API_ADC_Busy_of_SoftFinish(ADA) != 0)
	{	return;
	}
	else
	{
		while((ADA->MOD2) != 0)
		{
			;
		}
		ultemp = ADA->REG4;
		slVdcSum = (INT32)(ultemp & 0x0000FFF0);
		ultemp = ADA->REG5;
		slVdcSum += (INT32)(ultemp & 0x0000FFF0);
		ultemp = ADA->REG6;
		slVdcSum += (INT32)(ultemp & 0x0000FFF0);

		slDetect_CurVoltage = slVdcSum / 3;

		ucVdcCnt++;
		ulVdcSum += slDetect_CurVoltage;

		API_ADC_Start_of_SoftConvert(ADA);
		if(ucVdcCnt >= 20000)
		{
			ulDetect_CurVoltage = (UINT16)(ulVdcSum / 20000);
			ulVdcSum = 0;
			ucVdcCnt = 0;
		}
		else
		{;}
	}
	*/
}

UINT8 Is_DC_Link_Valid()
{
	UINT8 ucDCLinkError = CLR;
	UINT16 ucClacVdcReal = CLR;

	ucClacVdcReal = (UINT16)(GetVdcAvg() / VDC_SCALE);

	if(ucClacVdcReal >= VDC_HIGH_LIMIT_VOLTAGE)
	{
		ucDCLinkError = SET;
	}
	else
	{
		;
	}

	if(ucClacVdcReal <= VDC_LOW_LIMIT_VOLTAGE)
	{
		ucDCLinkError = SET;
	}
	else
	{
		;
	}

	return ucDCLinkError;
}

UINT16 GetVdcAvg()
{
	return (UINT16)((ulDetect_CurVoltage * 1719) / 1000);
}




